home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 14041 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.5 KB

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Beginner need help??????????????
  5. Date: Thu, 11 Apr 96 14:10:12 GMT
  6. Organization: none
  7. Distribution: world
  8. Message-ID: <829231812snz@genesis.demon.co.uk>
  9. References: <4kem82$5j3@dewey.csun.edu> <Pine.A32.3.91.960410160516.110349D-100000@black.weeg.uiowa.edu>
  10. Reply-To: fred@genesis.demon.co.uk
  11. X-NNTP-Posting-Host: genesis.demon.co.uk
  12. X-Newsreader: Demon Internet Simple News v1.27
  13. X-Mail2News-Path: genesis.demon.co.uk
  14.  
  15. In article <Pine.A32.3.91.960410160516.110349D-100000@black.weeg.uiowa.edu>
  16.            robinson@blue.weeg.uiowa.edu "The Amorphous Mass" writes:
  17.  
  18. >> ----------program 3---------------------------
  19. >> #include <stdio.h>
  20. >> 
  21. >> int   integer;
  22. >> float floating;
  23. >> main()
  24. >> {
  25. >>   floating = 7.0 / 22.0;
  26. >>   integer = floating;
  27. >>   printf("The value of integer is %f\n", integer);
  28. >>   return (0);
  29. >> }
  30. >> 
  31. >> ???? The answer should be 0.31818 but compiler give me 0.000000 ?????
  32. >
  33. >  In this case, floating gets 0.31818, but when you assign it to an int, 
  34. >it truncates the fractional part.  So integer == 0.  Then you tell 
  35. >printf() to print integer's value (0) as a float, and you get 0.000000.  
  36.  
  37. However it could have printed anything because trying to use %f to
  38. print an integer argument results in undefined behaviour.
  39.  
  40. -- 
  41. -----------------------------------------
  42. Lawrence Kirby | fred@genesis.demon.co.uk
  43. Wilts, England | 70734.126@compuserve.com
  44. -----------------------------------------
  45.